#include "wubi_symbol.h"
#include "src/symbols/radicals/radical_analyzer.h"

WuBiSymbol::WuBiSymbol(const std::string& wubiCode, const std::string& chineseChar)
    : code(wubiCode), character(chineseChar) {
    // 分析字根结构
    radicals = RadicalAnalyzer::analyzeCharacter(chineseChar);
    
    // 初始化语义向量
    for (const auto& radical : radicals) {
        semanticVectors.push_back(RadicalSemantic::getSemanticVector(radical));
    }
}

SemanticVector WuBiSymbol::computeSemanticVector() const {
    SemanticVector result;
    // 基于字根语义向量计算复合语义
    for (size_t i = 0; i < semanticVectors.size(); ++i) {
        double weight = 1.0 / (i + 1);  // 位置权重
        result = result + semanticVectors[i] * weight;
    }
    return result;
}

double WuBiSymbol::similarity(const WuBiSymbol& other) const {
    // 计算语义相似度
    auto thisVector = computeSemanticVector();
    auto otherVector = other.computeSemanticVector();
    return thisVector.cosineSimilarity(otherVector);
}

std::string WuBiSymbol::toString() const {
    return character + "(" + code + ")";
}